<?php

//podstawowe funkcje 
function ConnectToMySQL($host, $user, $pass, $db) {
    $link = mysql_connect($host, $user, $pass);
    if
    (!$link) {
        die('Could not connect: ' . mysql_error());
    } else {
        echo 'MySQL connected successfully <br />';
        $db = mysql_select_db($db);
        if (!$db) {
            die('Could not select database ' . mysql_error());
        } else {
            echo 'Database selected successfully <br />';
        }
    }
}

//users handlers
function GetPlayerData($player) {
    $query = mysql_query("SELECT * FROM users WHERE Login = '" . $player . "';");
    if (!$query) {
        die("There is problem with GetPlayerData, error: " . mysql_error());
    } else {
        $ar = mysql_fetch_assoc($query);
        return $ar;
    }
}

function CreateNewPlayer($login, $pass) {
    $query = mysql_query("INSERT INTO users (Login,Pass) VALUES ('" . $login . "',md5('" . $pass . "'));");
    if (!$query) {
        die("There is problem with CreateNewPlayer function, error: " . mysql_error());
    }
}

function DeletePlayer($login) {
    $query = mysql_query("DELETE FROM users WHERE Login = '" . $login . "';");
    if (!$query) {
        die("There is problem with DeletePlayer function, error: " . mysql_error());
    }
}

?>